Completed
Push — master ( 598926...1a164b )
by Fike
44s queued 17s
created

Level.keys.forEach   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 1
dl 0
loc 11
rs 9.4285
nop 1
1
/**
2
 * @typedef {object} Level~Element
3
 * @property {string} id
4
 * @property {int} weight
5
 * @property {boolean} implicit
6
 */
7
8
/**
9
 * @enum
10
 *
11
 * @property {Level~Element} All
12
 * @property {Level~Element} Trace
13
 * @property {Level~Element} Debug
14
 * @property {Level~Element} Info
15
 * @property {Level~Element} Notice
16
 * @property {Level~Element} Warn
17
 * @property {Level~Element} Error
18
 * @property {Level~Element} Off
19
 */
20
var Level = {}
21
22
Level.keys = ['All', 'Trace', 'Debug', 'Info', 'Notice', 'Warn', 'Error']
23
Level.values = []
24
Level.explicit = []
25
Level.implicit = []
26
var implicit = ['All', 'Off']
27
Level.keys.forEach(function (id) {
28
  var level = {
29
    id: id,
30
    weight: Level.keys.indexOf(id) + 1,
31
    implicit: implicit.indexOf(id) > -1
32
  }
33
  Level[id] = level
34
  Level.values.push(level)
35
  var target = level.implicit ? Level.implicit : Level.explicit
36
  target.push(level)
37
})
38
39
Level.find = function (input) {
40
  input = input && input.toLowerCase ? input.toLowerCase() : input
41
  return Level.keys.reduce(function (carrier, id) {
42
    return input === id.toLowerCase() || input === Level[id] ? Level[id] : carrier
43
  }, null)
44
}
45
46
module.exports = {
47
  Level: Level
48
}
49